import { computed, provide, ref } from 'vue';
import type { PropType } from 'vue';
// import { NOOP } from '../../utils';
import type { Column, Columns, DataSource } from '../../types';

const NOOP = () => {};

export const props = {
  data: { type: Array, default: [] },
  // data model
  // dataSource: {
  //   type: Object,
  //   required: true,
  // } as any as PropType<DataSource<unknown>>,

  // callback
  onExpand: { type: Function, default: NOOP },
  onAddRow: { type: Function, default: NOOP },
  onAddItem: { type: Function, default: NOOP },
  onCopy: { type: Function, default: NOOP },
  onRemove: { type: Function, default: NOOP },
  onEdit: { type: Function, default: NOOP },
  onSave: { type: Function, default: NOOP },
  onApproval: { type: Function, default: NOOP },
};

type RegisterColumn = (column: Column) => void;

export interface ZTableExpandContext {
  registerColumn: RegisterColumn;
}

// 格式化成 ant-design 列配置
export function formatColumn(column: Column) {
  const { label: title, prop: dataIndex, ...props } = column;
  const def = { width: '1' };
  return { title, dataIndex, ...def, ...props };
}

// <table-item>的列信息
export const columns = ref<Columns>([]);

// export const tableColumns = computed(() => {
//   const format = columns.value.map((col) => formatColumn(col));
//   format.push({
//     title: '操作',
//     dataIndex: 'operation',
//     width: '1',
//   });
//   return format;
// });

// table-item用来注册column信息
const registerColumn = (column: Column) => {
  columns.value.push(column);
};

export const context = {
  registerColumn,
};
